Use AllowMultiple as signal for array query parameters#620
Conversation
When a restful parameter DataType is prefixed with '[]' (e.g. '[]string', '[]integer'), emit type: array with the correct items sub-schema instead of treating it as a scalar type. This allows upstream callers to pass compound DataType values through restful plumbing without losing the array semantics, fixing OpenAPI spec generation for parameters like PodExecOptions.Command []string. Related: kubernetes/kubernetes#140050
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rithwik-01 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @rithwik-01! |
…le/Explode for AllowMultiple - Check OpenAPITypeFormat(dataType) before stripping [] prefix so known scalar types like "[]byte" (base64-encoded string) aren't incorrectly emitted as array[uint8]. - V2: set CollectionFormat="multi" when array parameter has AllowMultiple. - V3: set Style="form", Explode=true when array parameter has AllowMultiple.
Jefftree
left a comment
There was a problem hiding this comment.
See if you can align to use AllowMultiple instead.
Replace []-prefix-based array detection with AllowMultiple() as the canonical signal for emitting type: array in OpenAPI schemas. The [] prefix is only stripped to derive the element type. V2: Always set CollectionFormat="multi" for AllowMultiple params. V3: Always set Style="form" and Explode=true for AllowMultiple params. []string without AllowMultiple is treated as a misconfiguration.
|
@Jefftree Thank you for the suggestion.
|
|
/assign |
Use
AllowMultiple()as the signal for emittingtype: arrayin OpenAPI schemas instead of detecting a[]prefix on DataType. WhenAllowMultiple()is true, the[]prefix is only stripped to derive the element type.Changes:
pkg/builder/openapi.go(v2): array detection viaAllowMultiple(),CollectionFormat: "multi"always set for array paramspkg/builder3/openapi.go(v3): same, withStyle: "form"+Explode: truefor array params[]bytestays scalar naturally throughOpenAPITypeFormat: no special guard needed[]stringwithoutAllowMultipleintentionally errors as a misconfigurationrestfuladapter.ParamAdapter(same adapter as runtime)Relationship to kubernetes/kubernetes#140050
This PR is a necessary precondition for fixing that issue, but does not close it alone. The Kubernetes apiserver's
typeToJSONfunction (staging/src/k8s.io/apiserver/pkg/endpoints/installer.go) explicitly strips[]string→"string"and[]int32→"integer"with a TODO referencing the go-restful limitation this PR addresses. A companion PR to remove those cases fromtypeToJSONis needed to fully resolve the issue.Refs: kubernetes/kubernetes#140050